package com.bank.doman.auth.dao;

import com.bank.doman.auth.dao.mapper.UserRoleMapper;
import com.bank.doman.auth.dao.model.UserRole;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 类RoleGrantDao.java的实现描述：TODO
 *
 * @author zach
 * @Date :2020-06-23 14:41.
 */
@Repository
public class UserRoleDao {

    @Resource
    private UserRoleMapper userRoleMapper;

    /**
     * 清空用户角色
     * @param userId
     */
    public void deleteRoleMenu(String userId) {
        UserRole roleMenu = new UserRole();
        roleMenu.setUserId(userId);
        userRoleMapper.delete(roleMenu);
    }

    public List<UserRole> getUserRole(String userId) {
        UserRole userRole = new UserRole();
        userRole.setUserId(userId);
        return userRoleMapper.select(userRole);
    }

    public void addRoleMenu(List<String> roleIds, String userId) {
        List<UserRole> userRoles = new ArrayList<>();
        for (String roleId : roleIds) {
            UserRole userRole = new UserRole();
            userRole.setRoleId(roleId);
            userRole.setUserId(userId);
            userRoles.add(userRole);
        }
        userRoleMapper.insertList(userRoles);
    }

    public void changeRoleId(Map<String, String> map) {
        userRoleMapper.changeRoleId(map);
    }

    public void changeUserId(Map<String, String> map) {
        userRoleMapper.changeUserId(map);
    }
}
